package org.example.beans;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

/**
 * 应用作用域Bean - 整个Web应用创建一个实例
 * 仅在Web环境中可用，类似于Singleton，但是在ServletContext级别
 */
@Component
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ApplicationScopeBean {
    
    private final String instanceId;
    
    public ApplicationScopeBean() {
        this.instanceId = "ApplicationScopeBean-" + System.currentTimeMillis() + "-" + this.hashCode();
        System.out.println("创建ApplicationScopeBean实例: " + instanceId);
    }
    
    public String getInstanceId() {
        return instanceId;
    }
    
    public void doSomething() {
        System.out.println("ApplicationScopeBean执行任务，实例ID: " + instanceId);
    }
} 